import formatTime from '../../../../style/formatTime'
const MAX_LIMIT=10 
var app = getApp()
const db = wx.cloud.database();
Page({ 
 
  /** 
   * 页面的初始数据 
   */ 
  data: { 
    tupian: [],
    tiezi: [],
    shipin: [],
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
  }, 
  
//  tab切换逻辑
swichNav: function( e ) {

    var that = this;

    if( this.data.currentTab === e.target.dataset.current ) {
        return false;
    } else {
        that.setData( {
            currentTab: e.target.dataset.current
        })
    }
},

bindChange: function( e ) {

    var that = this;
    that.setData( { currentTab: e.detail.current });

},

  /** 
   * 生命周期函数--监听页面加载 
   */ 
  onLoad: function (options) { 
    var that = this;

    /**
     * 获取当前设备的宽高
     */
    wx.getSystemInfo( {

        success: function( res ) {
            that.setData( {
                winWidth: res.windowWidth,
                winHeight: res.windowHeight
            });
        }

    });


this._getListByCloudfu() 
this._getListByCloudfu1() 
this._getListByCloudfu2() 

  }, 

// 漫贴
_getListByCloudfu() {
  let that = this;
  wx.cloud.callFunction({
    name: 'getOpenid',
    complete: res => {
      console.log('云函数获取到的openid: ', res.result.openid)
      db.collection('meitu-pl').where({
        // 查询条件
        openidsd: res.result.openid,
        ip:300,
      })
      .get()
      .then(res => {
        // 查询数据成功 
        for (var i = 0; i < res.data.length; i++) { 
          res.data[i].createTime = formatTime(new Date(res.data[i].createTime))
       }
        that.setData({
          tiezi:res.data
        })
      }).catch(err => {
        // 查询数据失败
        console.log(err)
      })
    }
  })
},
goComment(event) {
  wx.navigateTo({
    url: '/pages/index/mantie/mantie-nr/mantie-nr?tieziId=' + event.currentTarget.dataset.tieziid,
  })
},

// 视频
_getListByCloudfu2() {
  let that = this;
  wx.cloud.callFunction({
    name: 'getOpenid',
    complete: res => {
      console.log('云函数获取到的openid: ', res.result.openid)
      db.collection('meitu-pl').where({
        // 查询条件
        openidsd: res.result.openid,
        ip:400,
      })
      .get()
      .then(res => {
        // 查询数据成功 
        for (var i = 0; i < res.data.length; i++) { 
          res.data[i].createTime = formatTime(new Date(res.data[i].createTime))
       }
        that.setData({
          shipin:res.data
        })
      }).catch(err => {
        // 查询数据失败
        console.log(err)
      })
    }
  })
},
goComment2(event) {
 
  wx.navigateTo({
    url: '/pages/index/shipin/shipin-nr/shipin-nr?shipinId=' + event.currentTarget.dataset.shipinid,
  })
},

// 图片

_getListByCloudfu1() {
  let that = this;
  wx.cloud.callFunction({
    name: 'getOpenid',
    complete: res => {
      console.log('云函数获取到的openid: ', res.result.openid)
      db.collection('meitu-pl').where({
        // 查询条件
        openidsd: res.result.openid,
        ip:200,
      })
      .get()
      .then(res => {
        // 查询数据成功 
        for (var i = 0; i < res.data.length; i++) { 
          res.data[i].createTime = formatTime(new Date(res.data[i].createTime))
       }
        that.setData({
          tupian:res.data
        })
      }).catch(err => {
        // 查询数据失败
        console.log(err)
      })
    }
  })
},
goComment1(event) {
 
  wx.navigateTo({
    url: '/pages/index/meitu/meitu-nr/meitu-nr?tupianId=' + event.currentTarget.dataset.tupianid,
  })
},

  /** 
   * 生命周期函数--监听页面初次渲染完成 
   */ 
  onReady: function () { 
 
  }, 
 
  /** 
   * 生命周期函数--监听页面显示 
   */ 
  onShow: function () { 
 
  }, 
 
  /** 
   * 生命周期函数--监听页面隐藏 
   */ 
  onHide: function () { 
 
  }, 
 
  /** 
   * 生命周期函数--监听页面卸载 
   */ 
  onUnload: function () { 
 
  }, 
 
  /** 
   * 页面相关事件处理函数--监听用户下拉动作 
   */ 
  onPullDownRefresh: function () { 
    this._getListByCloudfu() 
  }, 
 
  /** 
   * 页面上拉触底事件的处理函数 
   */ 
  onReachBottom: function () { 
    this._getListByCloudfu() 
  }, 
 
  /** 
   * 用户点击右上角分享 
   */ 
  onShareAppMessage: function () { 
 
  } 
})
